# -*- coding: utf-8 -*-
# created on 2017/04/11

from mathsolver.functions.base import BaseFunction, BaseVariable
from mathsolver.functions.hanshu.dandiaoqujian import DiZengQuJian, DiJianQuJian
from mathsolver.functions.hanshu.helper import check_inter
from mathsolver.functions.hanshu.jiou_panduan import OddEven
from mathsolver.functions.hanshu.lingdian_geshu import LingDianGeShu


class JiOuPanDuan(BaseFunction):
    """判断函数是否是 奇/偶 函数"""

    def solver(self, *args):
        func, jiou = args
        assert "偶函数" in jiou or "奇函数" in jiou or "非奇非偶函数" in jiou

        jiouxing = OddEven().solver(func).output[0]
        result = jiouxing in jiou
        self.output.append(BaseVariable(result))
        return self


class PanDuanDanDiao(BaseFunction):
    """判断函数在给定区间上面是否是单调 增/减 函数
    输入：函数，区间，递增/递减
    输出：BaseVariable(True/False)"""

    def solver(self, *args):
        func, qujian, dandiao = args[0], check_inter(args[1]), args[2]

        if "增" in dandiao:
            dandiao_interval = DiZengQuJian().solver(func).output[0].value
        else:
            dandiao_interval = DiJianQuJian().solver(func).output[0].value

        result = qujian.issubset(dandiao_interval)
        self.output.append(BaseVariable(result))
        return self


class PanDuanLingDianCunZai(BaseFunction):
    """判断零点是否存在"""

    def solver(self, *args):
        geshu = LingDianGeShu().solver(*args).output[0].sympify()
        result = geshu > 0
        self.output.append(BaseVariable(result))
        self.label.add("判断零点是否存在")
        return self


if __name__ == '__main__':
    pass
